<?php
class Core_Business_Rulemenu extends Core_Business_Abstract {
	private $_ruleid;
	private $_menuitemid;
	
	public function getRuleid() {return $this->_ruleid;}
	public function setRuleid($value) {$this->_ruleid=$value;}
	
	public function getMenuitemid() {return $this->_menuitemid;}
	public function setMenuitemid($value) {$this->_menuitemid=$value;}
	
	public function getRole() {
		return Core_Business_Rule::getRuleById($this->_ruleid);
	}
	public function getMenuitem() {
		return Core_Business_Menuitem::getMenuById($this->_menuitemid);
	}
	
	public static function allow($menuitem,$roleid) {
		$map = new Core_Data_Mappers_Rulemenu();
		$data  = $map->fetchAll(array('menuitemid = ?'=>$menuitem->Id,"ruleid = ?"=>$roleid));
		if(count($data)>0) {
			return true;
		}
		return  false;
	}
	public static function getMenuitemLevel0($ruleid) {
		
		$map = new Core_Data_Mappers_Menuitem();
		$query = $map->getDbTable()->select(Zend_Db_Table::SELECT_WITHOUT_FROM_PART);
		$query->setIntegrityCheck(false);
		$query=$query->from(array('r'=>"rulemenu"))
				->join(array('m'=>'menuitem'), 'r.menuitemid=m.id and m.parentid is null',"*")
				->where("r.ruleid = ?",$ruleid)
				->where("m.disabled=0");
		$collection = $map->fetchQuery($query);
		return $collection;
	} 
	
}